package com.qeegoo.b2bautozityp.moudle.good.view;

import android.os.Bundle;

import com.qeegoo.b2bautozityp.R;
import com.qeegoo.b2bautozityp.databinding.FragGoodsPrepertyBinding;
import com.qeegoo.b2bautozityp.injector.component.DaggerGoodsFragmentComponent;
import com.qeegoo.b2bautozityp.moudle.base.BaseFragment;
import com.qeegoo.b2bautozityp.moudle.good.model.GoodsPropertyBean;
import com.qeegoo.b2bautozityp.moudle.good.viewmodel.GoodsPropertyViewModel;

import java.util.ArrayList;

import javax.inject.Inject;

import base.lib.widget.recyclerview.DividerLinearItemDecoration;

/**
 * 王少岩 在 2017/9/19 创建了它
 */

public class GoodsPropertyFragment extends BaseFragment<FragGoodsPrepertyBinding> {
    @Inject
    GoodsPropertyViewModel mViewModel;

    public static GoodsPropertyFragment newInstance(String title, String label, String info, ArrayList<GoodsPropertyBean.GoodsProperty> goodsProperties) {
        GoodsPropertyFragment fragment = new GoodsPropertyFragment();
        Bundle bundle = new Bundle();
        bundle.putString("title", title);
        bundle.putString("label", label);
        bundle.putString("info", info);
        bundle.putSerializable("goodsProperties", goodsProperties);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.frag_goods_preperty;
    }

    @Override
    protected void initInjector() {
        DaggerGoodsFragmentComponent.builder().appComponent(getAppComponent()).fragmentComponent(getFragmentComponent()).build().inject(this);
    }

    @Override
    protected void initViews() {
        mViewModel.title.set(getArguments().getString("title"));
        if (getArguments().getSerializable("goodsProperties") != null)
            mViewModel.setGoodsProperties(getArguments().getString("label"), getArguments().getString("info"), (ArrayList<GoodsPropertyBean.GoodsProperty>) getArguments().getSerializable("goodsProperties"));
        else
            mViewModel.getWareHouse(getArguments().getString("label"), getArguments().getString("info"));
        mBinding.setViewModel(mViewModel);
        mBinding.rvGoodsProperty.addItemDecoration(new DividerLinearItemDecoration(getActivity(), DividerLinearItemDecoration.HORIZONTAL_LIST, R.drawable.divider_h));
    }
}
